//数组并集
/**
 * 求两个数组的并集
 */
const union = (a, b) => Array.from(new Set([...a, ...b]));

/**
 * 求两个数组的交集
 */
const intersect = (a, b) => {
  const arr = new Set();
  a.forEach((item) => {
    if (b.includes(item)) {
      arr.add(item);
    }
  });
  return Array.from(arr);
};

console.log(intersect([1, 2, 3], [3, 4, 5])); // 期望结果: [3]

console.log(intersect([1, 2, 3], [4, 5, 6])); // 期望结果: []

console.log(intersect([1, 2, 3], [1, 2, 3])); // 期望结果: [1, 2, 3]

console.log(intersect([], [1, 2, 3])); // 期望结果: []
console.log(intersect([1, 2, 3], [])); // 期望结果: []

console.log(intersect([1, 2, 2, 3], [2, 2, 3])); // 期望结果: [2, 3]

console.log(intersect([1, 2, 3], [undefined, 2, 3])); // 期望结果: [2, 3]

console.log(intersect([1, "hello", true], [true, 1, "hello"])); // 期望结果: [1, "hello", true]
